package com.ruoyi.web.controller.system;

import java.util.List;

import com.ruoyi.system.service.IHaoyoutuijianService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Haoyoutuijian;
import com.ruoyi.framework.web.base.BaseController;
import com.ruoyi.common.page.TableDataInfo;
import com.ruoyi.common.base.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 好友推荐 信息操作处理
 * 
 * @author ruoyi
 * @date 2019-07-16
 */
@Controller
@RequestMapping("/system/haoyoutuijian")
public class HaoyoutuijianController extends BaseController
{
    private String prefix = "system/haoyoutuijian";
	
	@Autowired
	private IHaoyoutuijianService haoyoutuijianService;
	
	@RequiresPermissions("system:haoyoutuijian:view")
	@GetMapping()
	public String haoyoutuijian()
	{
	    return prefix + "/haoyoutuijian";
	}
	
	/**
	 * 查询好友推荐列表
	 */
	@RequiresPermissions("system:haoyoutuijian:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Haoyoutuijian haoyoutuijian)
	{
		startPage();
        List<Haoyoutuijian> list = haoyoutuijianService.selectHaoyoutuijianList(haoyoutuijian);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出好友推荐列表
	 */
	@RequiresPermissions("system:haoyoutuijian:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Haoyoutuijian haoyoutuijian)
    {
    	List<Haoyoutuijian> list = haoyoutuijianService.selectHaoyoutuijianList(haoyoutuijian);
        ExcelUtil<Haoyoutuijian> util = new ExcelUtil<Haoyoutuijian>(Haoyoutuijian.class);
        return util.exportExcel(list, "haoyoutuijian");
    }
	
	/**
	 * 新增好友推荐
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存好友推荐
	 */
	@RequiresPermissions("system:haoyoutuijian:add")
	@Log(title = "好友推荐", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Haoyoutuijian haoyoutuijian)
	{		
		return toAjax(haoyoutuijianService.insertHaoyoutuijian(haoyoutuijian));
	}

	/**
	 * 修改好友推荐
	 */
	@GetMapping("/edit/{haoyoutuijianId}")
	public String edit(@PathVariable("haoyoutuijianId") Integer haoyoutuijianId, ModelMap mmap)
	{
		Haoyoutuijian haoyoutuijian = haoyoutuijianService.selectHaoyoutuijianById(haoyoutuijianId);
		mmap.put("haoyoutuijian", haoyoutuijian);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存好友推荐
	 */
	@RequiresPermissions("system:haoyoutuijian:edit")
	@Log(title = "好友推荐", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Haoyoutuijian haoyoutuijian)
	{		
		return toAjax(haoyoutuijianService.updateHaoyoutuijian(haoyoutuijian));
	}
	
	/**
	 * 删除好友推荐
	 */
	@RequiresPermissions("system:haoyoutuijian:remove")
	@Log(title = "好友推荐", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(haoyoutuijianService.deleteHaoyoutuijianByIds(ids));
	}
	
}
